/**
 * 任务状态常量
 */
export const TASK_STATE = {
	/** 待核对 */
	PENDING: 1,
	/** 核对排队中 */
	QUEUING: 2,
	/** 核对中 */
	CHECKING: 3,
	/** 核对完成 */
	COMPLETED: 4,
	/** 核对失败 */
	FAILED: 5,
	/** 停止核对 */
	STOPPED: 6,
	/** 核对已停止(核对完成) */
	STOPPED_COMPLETED: 64,
	/** 核对已停止(核对失败) */
	STOPPED_FAILED: 65
} as const

/**
 * 总表状态常量
 */
export const FILE_STATE = {
	/** 待导入 */
	PENDING: 1,
	/** 导入中 */
	IMPORTING: 2,
	/** 导入成功 */
	SUCCESS: 3,
	/** 导入失败 */
	FAILED: 4
} as const

/**
 * 任务状态标签类型映射
 */
export const TASK_STATE_TAG_MAP: Record<number, string> = {
	[TASK_STATE.PENDING]: 'warning',
	[TASK_STATE.QUEUING]: 'info',
	[TASK_STATE.CHECKING]: 'primary',
	[TASK_STATE.COMPLETED]: 'success',
	[TASK_STATE.FAILED]: 'danger',
	[TASK_STATE.STOPPED]: 'danger',
	[TASK_STATE.STOPPED_COMPLETED]: 'danger',
	[TASK_STATE.STOPPED_FAILED]: 'danger'
}

/**
 * 任务状态文本映射
 */
export const TASK_STATE_TEXT_MAP: Record<number, string> = {
	[TASK_STATE.PENDING]: '待核对',
	[TASK_STATE.QUEUING]: '核对排队中',
	[TASK_STATE.CHECKING]: '核对中',
	[TASK_STATE.COMPLETED]: '核对完成',
	[TASK_STATE.FAILED]: '核对失败',
	[TASK_STATE.STOPPED]: '停止核对',
	[TASK_STATE.STOPPED_COMPLETED]: '核对已停止(核对完成)',
	[TASK_STATE.STOPPED_FAILED]: '核对已停止(核对失败)'
}
/**
 * 总表状态标签类型映射
 */
export const FILE_STATE_TAG_MAP: Record<number, string> = {
	[FILE_STATE.PENDING]: 'warning',
	[FILE_STATE.IMPORTING]: 'primary',
	[FILE_STATE.SUCCESS]: 'success',
	[FILE_STATE.FAILED]: 'danger'
}
/**
 * 总表状态文本映射
 */
export const FILE_STATE_TEXT_MAP: Record<number, string> = {
	[FILE_STATE.PENDING]: '待导入',
	[FILE_STATE.IMPORTING]: '导入中',
	[FILE_STATE.SUCCESS]: '导入成功',
	[FILE_STATE.FAILED]: '导入失败'
}

/**
 * 获取任务状态标签类型
 */
export function getTaskStateTag(state: number): string {
	return TASK_STATE_TAG_MAP[state] || 'info'
}

/**
 * 获取任务状态文本
 */
export function getTaskStateText(state: number): string {
	return TASK_STATE_TEXT_MAP[state] || '未知状态'
}
/**
 * 获取总表状态标签类型
 */
export function getFileStateTag(state: number): string {
	return FILE_STATE_TAG_MAP[state] || 'info'
}
/**
 * 获取总表状态文本
 */
export function getFileStateText(state: number): string {
	return FILE_STATE_TEXT_MAP[state] || '-'
}

/**
 * 判断任务是否处于核对中状态
 */
export function isTaskChecking(state: number): boolean {
	return state === TASK_STATE.QUEUING || state === TASK_STATE.CHECKING
}
/**
 * 判断是否显示开始核对
 */
export function isShowExecCheck(row: any): boolean {
	return row.task_state !== TASK_STATE.QUEUING && row.task_state !== TASK_STATE.CHECKING && row.task_state !== TASK_STATE.COMPLETED && row.source_file_state === FILE_STATE.SUCCESS
}
/**
 * 判断是否显示编辑
 * @param row 
 * @returns boolean
 */
export function isShowUpdate(row: any): boolean {
	return row.source_file_state !== FILE_STATE.PENDING && row.source_file_state !== FILE_STATE.IMPORTING && row.task_state !== TASK_STATE.QUEUING && row.task_state !== TASK_STATE.CHECKING && row.task_state !== TASK_STATE.COMPLETED
}
/**
 * 判断是否显示删除
 * @param row 
 * @returns boolean
 */
export function isShowDestroy(row: any): boolean {
	return row.source_file_state !== FILE_STATE.PENDING && row.source_file_state !== FILE_STATE.IMPORTING
}
/**
 * 判断总表是否处于导入中状态
 */
export function isFileImporting(state: number): boolean {
	return state === FILE_STATE.IMPORTING
}

